#ifndef __VTOR_STRING_H__
#define __VTOR_STRING_H__

#ifdef __cplusplus
extern "C" {
#endif

#include "vtor_elec_module_config.h"

#ifdef __VTOR_STRING__

typedef enum
{
	VtorVar_Void=0,
	VtorVar_Char,
	VtorVar_Int,
	VtorVar_Hex,
	VtorVar_Float,
	VtorVar_String,
	VtorVar_Memory,
	VtorVar_HexString,
}VtorVarType;

typedef struct
{
	int32_t intVar;
	float floatVar;
	uint8_t strVar[20];
	VtorVarType type;
}VtorVar;

// 小端控制宏，stm32等是小端，所以默认打开，只在AppendMemory中使用
#define __VTOR_STRING_CONFIG_LITTLE_ENDIAN__


void VtorString_Clear(uint8_t* str);
int32_t VtorString_Length(const uint8_t* str);
uint8_t* VtorString_Preprocess(uint8_t* str);
void VtorString_AdjustControlChar(uint8_t* str);

// 基础字符串操作：比较字符串，查找数字，查找字符串，截断原字符串，并返回子串头
int8_t VtorString_CmpString(const uint8_t* str1, const uint8_t* str2);
int16_t VtorString_GetSimilarity(const uint8_t* str1, const uint8_t* str2);
uint8_t* VtorString_FindInt(uint8_t* str, int32_t* num);
uint8_t* VtorString_FindFloat(uint8_t* str, float* num);
uint8_t* VtorString_FindString(uint8_t* oriStr, uint8_t* dstStr);
uint8_t* VtorString_CutString(uint8_t* str, int32_t* subStrAddr);
uint8_t* VtorString_CutHexString(uint8_t* str, int32_t* subStrAddr);
uint8_t* VtorString_FindVariable(uint8_t* str, VtorVar* var);

// 寻找下一个类型，字符串，或者整形
uint8_t* VtorString_GetNextValueType(uint8_t* str, int8_t* valType);

// 基础字符串操作：字符串末尾增加数字，增加字符串
#ifdef __VTOR_STRING_CONFIG_PRINTF_BY_VSPRINTF__
int16_t VtorString_Printf(const char *format, ...);
#endif

// 拥抱安全的字符串（参数中带有长度指针）
uint8_t* VtorString_AppendChar(uint8_t* str, int32_t* len, const uint8_t ch);
uint8_t* VtorString_AppendInt(uint8_t* str, int32_t* len, int32_t num);
uint8_t* VtorString_AppendHex(uint8_t* str, int32_t* len, uint32_t num);
uint8_t* VtorString_AppendFloat(uint8_t* str, int32_t* len, float num);
uint8_t* VtorString_AppendString(uint8_t* str, int32_t* len, const uint8_t* str2);
uint8_t* VtorString_AppendMemory(uint8_t* str, int32_t* len, void* mem, int32_t cnt, int8_t width);


int32_t VtorString_PrintNumber(int32_t num, int8_t len); // 简单打印字符串

int32_t VtorString_ChanPrintString(uint32_t ch, uint8_t* str);
int32_t VtorString_Print(uint8_t* str);
int32_t VtorString_PrintBuffer(uint8_t* buf, int32_t len);

// 用户自行实现打印函数与接收单个字符函数
int32_t VtorString_ChanPrintBuffer(uint32_t ch, uint8_t* buf, int32_t len);

#endif // __VTOR_STRING_H__

#ifdef __cplusplus
}
#endif

#endif
